<!DOCTYPE html>

<head>
    <title>test</title>
    <script src="SObject.js"></script>
</head>

<body>
    <script type="text/javascript">

        let AClass = SObject.define("AClass");

        let BClass = SObject.define("BClass", AClass);

        let CClass = SObject.define("CClass", BClass,
            function () {
                this.name = 'Anyone';
            });
        let DClass = SObject.define("DClass", CClass,
            function () { }, {
            sayHello() {
                console.log('hello ' + this.name);
            }
        })
        let d = new DClass();
        d.sayHello();// hello Anyone

        let json = JSON.stringify(d);
        let d1 = JSON.parse(json,SObject.ObjectReviver);
        d1.sayHello();
        d1.name = 'Petter';
        d1.sayHello();
        d.sayHello();


        let TestSObject = SObject.define(
            "TestSObject",
            SObject,
            function () {
                this.testValue = 'test?';
            }, {
            test() {
                console.log(this.testValue + ' test!');
            },
            test1() {
                console.log(this.testValue + ' test!11');
            }
        });
        let test = new TestSObject();
        test.test();
        test.test1();

        // serialize
        let str = JSON.stringify(test)
        console.log(str);
        let test1 = JSON.parse(str, SObject.ObjectReviver);
        console.log(test1);
        test1.test();
        test1.testValue = "test1 value ";
        test1.test();
        test.test();

        // extends

        let SubClass = SObject.define(
            "SubClass",
            TestSObject,
            function () {
                this.testValue = 'test sub';
                this.subValue = "sub value";
            }, {
            testSub() {
                console.log(this.testValue + ' test!' + this.subValue);
            }
        });

        let subtest = new SubClass();
        subtest.test();
        subtest.test1();
        subtest.testSub();

        // serialize
        let strsub = JSON.stringify(subtest)
        console.log(strsub);
        let subtest1 = JSON.parse(strsub, SObject.ObjectReviver);
        console.log(subtest1);
        subtest1.test();
        subtest1.test1();
        subtest1.testSub();
        subtest1.testValue = "test1 value ";
        subtest1.test();
        subtest1.test1();
        subtest1.testSub();
        subtest.test();
        subtest.test1();
        subtest.testSub();
    </script>
</body>

</html>